/**
 * PFornecedor.java
 * Copyright (C) 2009 Jose Mauro da Silva Sandy
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

package persistencia.pessoas;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.Statement;
import negocio.pessoas.Fornecedor;
import plagio.postgres.ConnectionPostgres;
import utils.*;

/**
 *
 * @author jmsandy
 */
public class PFornecedor extends PPessoa{

    //<editor-fold defaultstate="collapsed" desc="Constructor">
    /**
     * Construtor padrao. Responsavel por realizar a persistencia de Fornecedor
     * @throws java.io.IOException
     */
    public PFornecedor() throws IOException{
    }
    //</editor-fold>

    //<editor-fold defaultstate="collapsed" desc="Methods">
    /**
     * Responsavel por recuperar uma lista de todos os objetos que satisfacam
     * a descricao fornecida.
     * @param descricao descricao a ser recuperada
     * @return lista contendo todos os objetos recuperados
     */
    public ResultSet recLstFornRel(String nome){
        ResultSet rs = null;
        // Lista de objetos de retorno
        StringBuilder query = this.formSelector();
        // Clausula where
        query.append(" WHERE " + K_COL_nome + " LIKE '" + nome + "%'");
        query.append(" AND " + K_COL_CLASSNAME + " = '");
        query.append((new Fornecedor()).getClassName() + "'");
        // Clausula order by
        query.append(" ORDER BY " + K_COL_nome);

        try{
            ConnectionPostgres conn = new ConnectionPostgres(); // nova conexao

            // Realiza a conexao com o servidor
            conn = ConnectionSystem.connectionSystem();

            Statement stat = conn.getConnection().createStatement();
            rs = stat.executeQuery(query.toString());
        }catch(Exception ex){
            Log.gravarLog(RedirectStackTrace.stackTraceToString(ex), this);
            error = true;
            rs = null;
        }
        return rs;
    }
    //</editor-fold>
}